<template>
    <div class="app-container app-containerMoney">
        <div class="filter-container">
            <!-- <region-selector style="width:338px;" :hideProvince="true" :hideCity="true" :hideArea="true" :province="region.province" :city="region.city" :area="region.area" @region="setAreaCode">
            </region-selector>
            <el-select style="marginRight:15px;" size="small" v-model="listQuery.defKey" placeholder="请选择业务类型">
              <el-option
                v-for="item in defKeyOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value">
                </el-option>
            </el-select> -->
            <el-date-picker size="small" style="marginRight:15px;" v-model="listQuery.queryTime" type="daterange"
                range-separator="-" start-placeholder="开始日期" value-format="timestamp" end-placeholder="结束日期">
            </el-date-picker>
            <el-button size="small" class="filter-item filter-itemBut" type="primary" icon="el-icon-search" @click="handleFilter">搜索</el-button>
        </div>
        <el-table :data="list" v-loading.body="listLoading" element-loading-text="Loading" border fit
            highlight-current-row>
            <el-table-column label="业务" align="center">
                <template slot-scope="scope">
                    {{scope.row.approvalKey | mapLabel('approvalKey')}}
                </template>
            </el-table-column>
            <el-table-column label="县区" align="center">
                <template slot-scope="scope">
                    {{scope.row.areaName}}
                </template>
            </el-table-column>
            <el-table-column label="拨款金额" align="center">
                <template slot-scope="scope">
                    {{scope.row.money}}
                </template>
            </el-table-column>
            <el-table-column label="备注" align="center">
                <template slot-scope="scope">
                    {{scope.row.remark}}
                </template>
            </el-table-column>
            <!-- <el-table-column label="拨款时间" align="center">
                <template slot-scope="scope">
                    123
                </template>
            </el-table-column>
            <el-table-column label="拨款说明" align="center">
                <template slot-scope="scope">
                    123
                </template>
            </el-table-column> -->
        </el-table>
        <div class="pagination-container">
            <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                :current-page="listQuery.page" :page-sizes="[10,20,30, 50]" :page-size="listQuery.size" layout="total, sizes, prev, pager, next, jumper"
                :total="total">
            </el-pagination>
        </div>
    </div>
</template>
<script>
import { queryDetailPage } from "@/api/money";
import RegionSelector from "@/components/RegionSelector";
export default {
  components: {
    RegionSelector
  },
  data() {
    return {
      list: null,
      total: 0,
      listLoading: true,
      username: "",
      listQuery: {
        page: 1,
        size: 10,
        areaCode: null,
        approvalKey: null,
        startTime: null,
        endTime: null,
        queryTime: [],
        sort: "+id"
      },
      defKeyOptions: this.$store.state.dict.options["approvalKey"],
      region: {
        province: "陕西省",
        city: "西安市",
        area: "阎良区",
        street: 0,
        community: 0
      }
    };
  },
  mounted: function() {
    this.fetchData();
  },
  methods: {
    fetchData() {
      this.listLoading = true;
      queryDetailPage(this.listQuery).then(response => {
        this.list = response.data.records;
        this.total = response.data.total;
        this.listLoading = false;
      });
      this.listLoading = false;
    },
    handleFilter() {
      if (this.listQuery.queryTime.length > 1) {
        this.listQuery.startTime = this.listQuery.queryTime[0] / 1000;
        this.listQuery.endTime = this.listQuery.queryTime[1] / 1000;
      }
      this.listQuery.page = 1;
      this.fetchData();
    },
    handleSizeChange(val) {
      if (this.listQuery.queryTime.length > 1) {
        this.listQuery.startTime = this.listQuery.queryTime[0] / 1000;
        this.listQuery.endTime = this.listQuery.queryTime[1] / 1000;
      }
      this.listQuery.size = val;
      this.fetchData();
    },
    handleCurrentChange(val) {
      if (this.listQuery.queryTime.length > 1) {
        this.listQuery.startTime = this.listQuery.queryTime[0] / 1000;
        this.listQuery.endTime = this.listQuery.queryTime[1] / 1000;
      }
      this.listQuery.page = val;
      this.fetchData();
    },
    setAreaCode(value) {
      if (value.code) {
        this.listQuery.areaCode = value.code;
      }
    }
  }
};
</script>

<style scoped>
.filter-container {
  margin-bottom: 20px;
  overflow: hidden;
}

.filter-container-option {
  display: flex;
  flex-wrap: nowrap;
  margin-bottom: 15px;
}

.pagination-container {
  margin-top: 25px;
  overflow: hidden;
  display: flex;
  justify-content: flex-end;
}

.app-containerMoney {
  margin-right: 20px;
}

.filter-itemBut {
  margin-left: 25px;
}
</style>